<template>
	<view class="content_view">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" :title="'上传隐患'">
		</u-navbar>
		<u-form :model="hiddenDangerForm" ref="hiddenDangerForm" label-width="100px" style="padding: 24rpx;">
			<u-form-item label-position="left" label="隐患名称" prop="name">
				<u-input type="text" :border="border" placeholder="请输入详细的隐患名称" v-model="hiddenDangerForm.name" />
			</u-form-item>
			<u-form-item label-position="left" label="隐患地点" prop="address">
				<u-input type="text" :border="border" placeholder="请输入详细的隐患地点" v-model="hiddenDangerForm.address" />
			</u-form-item>
			<u-form-item label-position="left" label="隐患描述" prop="remark">
				<u-input type="text" :border="border" placeholder="请填写具体情况描述" v-model="hiddenDangerForm.remark" />
			</u-form-item>
			<u-form-item label="区域名称" prop="regionName">
				<u-input type="select" :select-open="regionShow" placeholder="请选择区域" v-model="regionName"
					@click="regionShow=true"></u-input>
			</u-form-item>
			<u-form-item label-position="left" label="隐患图片" prop="abnormalPic">
				<u-image v-if="hiddenDangerForm.abnormalPic" width="50%" height="450rpx" :src="hiddenDangerForm.abnormalPic+'?x-oss-process=style/zip_app'" mode="aspectFit" >
					<u-loading slot="loading"></u-loading>
				</u-image>
				<u-image v-else width="50%" height="450rpx" :src="hiddenDangerForm.abnormalPic+'?x-oss-process=style/zip_app'" mode="aspectFit" @click="uploadPic">
					<view slot="error" style="font-size: 24rpx;">
						<u-icon name="plus"></u-icon>
					</view>
				</u-image>
			</u-form-item>
		</u-form>
		<u-select :default-value="defaultValue" mode="mutil-column-auto" :list="regionList" value-name="ucId"
			label-name="name" v-model="regionShow" @confirm="regionConfirm"></u-select>
		<u-button @click="submit" type="primary" style="margin: 24rpx;">生成隐患工单</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				border: true,
				hiddenDangerForm: {},
				regionShow: false,
				regionList: [],
				defaultValue: [0,0],
				rules: {
					name: [{
						required: true,
						message: '请输入隐患名称',
						trigger: ['blur'],
					}],
					address: [{
						required: true,
						message: '请输入隐患详细地址',
						trigger: ['blur'],
					}],
					remark: [{
						required: true,
						message: '请输入隐患详细描述',
						trigger: ['blur'],
					}],
					regionName: [{
						required: true,
						message: '请选择区域',
						trigger: ['change', 'blur'],
					}],
				}
			}
		},
		onShow() {
			this.getRegionList(this.hiddenDangerForm.standardId)
		},
		onLoad(e) {
			this.hiddenDangerForm.standardId=e.standardId
			this.hiddenDangerForm.equipmentId=e.equipmentId
		},
		methods: {
			submit() {
				this.$refs.hiddenDangerForm.validate(valid => {
					if (valid) {
						this.utils.request("/api/app/examine/addHiddenDanger", this
							.hiddenDangerForm,
							"post", "app", true).then(res => {
								uni.navigateBack({
									delta:1
								})
							}).catch(error => {
							console.log(error)
						})
					} else {
						console.log('保存失败');
					}
				});
			},
			getRegionList(val) {
				if(val!=null){
					this.utils.request("/api/app/examine/getRegionList", {standardId: val}, "post", "app", true).then(res => {
						this.regionList = res.data
					}).catch(error => {
						console.log(error)
					})
				}
			},
			regionConfirm(e) {
				e.map((val, index) => {
					this.hiddenDangerForm.regionId = e.ucId
					this.regionName = e.name
					// this.getInRegionVo()
				})
			},
			uploadPic(){
				window.native.h5Camera()
				window.native.getUri(res=>{
					this.hiddenDangerForm.abnormalPic = res.uri
					console.log(this.hiddenDangerForm)
				})
			}
		},
		onReady() {
			this.$refs.hiddenDangerForm.setRules(this.rules);
		},
	}
</script>

<style>

</style>
